﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DAL;
using DAL.Models;
using BAL;
using BAL.Infrastructure;
using BAL.Interfaces;

namespace BibliotecaVirtual.Controllers
{
    [Authorize(Roles = Libreria.Constantes.ADMINISTRADOR)]
    public class EditorialsController : Controller
    {
        public IEditorialsService BALEditorials = null;

        public EditorialsController(IEditorialsService EditorialService)
        {
            BALEditorials = EditorialService;
        }

        //
        // GET: /Editorials/

        public ViewResult Index()
        {
            return View(BALEditorials.GetAll());
        }

        //
        // GET: /Editorials/Details/5

        public ViewResult Details(long id)
        {
            object[] keys = new object[1] { id };
            Editorials item = BALEditorials.Find(keys);
            return View(item);
        }

        //
        // GET: /Editorials/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Editorials/Create

        [HttpPost]
        public ActionResult Create(Editorials item)
        {
            if (ModelState.IsValid)
            {
                BALEditorials.Create(item);
                return RedirectToAction("Index");  
            }

            return View(item);
        }
        
        //
        // GET: /Editorials/Edit/5
 
        public ActionResult Edit(long id)
        {
            object[] keys = new object[1] { id };
            Editorials item = BALEditorials.Find(keys);
            return View(item);
        }

        //
        // POST: /Editorials/Edit/5

        [HttpPost]
        public ActionResult Edit(Editorials item)
        {
            if (ModelState.IsValid)
            {
                BALEditorials.Edit(item);
                return RedirectToAction("Index");
            }
            return View(item);
        }

        //
        // GET: /Editorials/Delete/5
 
        public ActionResult Delete(long id)
        {
            object[] keys = new object[1] { id };
            Editorials item = BALEditorials.Find(keys);
            return View(item);
        }

        //
        // POST: /Editorials/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(long id)
        {
            object[] keys = new object[1] { id };
            Editorials item = BALEditorials.Find(keys);
            BALEditorials.Remove(item);
            return RedirectToAction("Index");
        }

    }
}